package com.ss.whisper2.exception;

import com.ss.whisper2.pojo.Result;
import com.ss.whisper2.pojo.State;
import com.ss.whisper2.service.impl.CourseServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.sql.SQLIntegrityConstraintViolationException;

@ControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {
	private static final Logger LOGGER = LoggerFactory.getLogger(GlobalExceptionHandler.class);

	@ExceptionHandler(GlobalException.class)
	public Result<String> dealWithGlobalException(GlobalException e) {
		return new Result<>(e.getState());
	}

	//@ExceptionHandler(Exception.class)
	public Result<String> dealWithException() {
		return new Result<>(State.ERROR);
	}

}
